﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Dao.BU;
using SMTC.Model.Domain;
using System.Data.Common;
using SMTC.Model.Model;
using SMTC.BO.Common;

namespace SMTC.BO.BU
{
    public class BUQueryServices
    {
        private BUQueryDao _dao = new BUQueryDao();

        /// <summary>
        /// 获取bulist
        /// </summary>
        /// <param name="BUName"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<SMT_BUModel> GetBUList(string BUName, string ModifyPerson, DateTime startTime, DateTime endTime)
        {
            BUName = DbValueProccess.StrProccess(BUName);
            ModifyPerson = DbValueProccess.StrProccess(ModifyPerson);
            startTime = DbValueProccess.DateTimeProccess(startTime);
            endTime = DbValueProccess.DateTimeProccess(endTime, false);

            return _dao.GetBUList(BUName, ModifyPerson, startTime, endTime);
        }

        /// <summary>
        /// 获取bulist供选择BU时使用
        /// </summary>
        /// <param name="BUName"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<SMT_BUModel> GetBUListForSelect(string BUName, string ModifyPerson, DateTime startTime, DateTime endTime)
        {
            BUName = DbValueProccess.StrProccess(BUName);
            ModifyPerson = DbValueProccess.StrProccess(ModifyPerson);
            startTime = DbValueProccess.DateTimeProccess(startTime);
            endTime = DbValueProccess.DateTimeProccess(endTime, false);

            return _dao.GetBUListForSelect(BUName, ModifyPerson, startTime, endTime);
        }

        /// <summary>
        /// 获取单个bu实体
        /// </summary>
        /// <param name="buid"></param>
        /// <returns></returns>
        public SMT_BUModel GetBu(string buid)
        {
            return _dao.GetBU(buid);
        }
        /// <summary>
        /// 获取domian的list
        /// </summary>
        /// <param name="BUName"></param>
        /// <param name="ModifyPerson"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<BUDomain> GetBuDomainList(string BUName, string ModifyPerson, DateTime startTime, DateTime endTime)
        {
            List<BUDomain> resultList = new List<BUDomain>();
            List<SMT_BUModel> list = this.GetBUList(BUName, ModifyPerson, startTime, endTime);
            foreach (var item in list)
            {
                BUDomain domain = new BUDomain();
                domain.BU = item;
                domain.LineList = _dao.GetLineList(item.BUID);
                resultList.Add(domain);
            }

            return resultList;
        }
        /// <summary>
        /// 获取单个的domain实体
        /// </summary>
        /// <param name="BUID"></param>
        /// <returns></returns>
        public BUDomain GetBuDomain(string BUID)
        {
            BUDomain domian = new BUDomain();
            domian.BU = this.GetBu(BUID);
            domian.LineList = _dao.GetLineList(BUID);
            return domian;
        }
    }
}
